package co.yixiang.modules.shop.rest;

import co.yixiang.aop.log.Log;
import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.shop.service.YxSalesCommissionService;
import co.yixiang.modules.shop.service.dto.YxSalesCommissionDto;
import co.yixiang.modules.shop.service.dto.YxSalesCommissionQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**业务员提成
* @author frq
* @date 2020-06-11
*/
@Api(tags = "业务员提成表管理")
@RestController
@RequestMapping("/api/yxSalesCommission")
public class YxSalesCommissionController {
    @Autowired
    private  YxSalesCommissionService yxSalesCommissionService;



    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check('yxSalesCommission:list')")
    public void download(HttpServletResponse response, YxSalesCommissionQueryCriteria criteria) throws IOException {
        List<YxSalesCommissionDto> list=yxSalesCommissionService.queryAll(criteria);
        if(list.isEmpty()){
            throw new BadRequestException("没有可以导出的数据");
        }
        yxSalesCommissionService.download(list, response);
    }

    @GetMapping
    @Log("查询业务员提成表")
    @ApiOperation("查询业务员提成表")
//    @PreAuthorize("@el.check('yxSalesCommission:list')")
    public ResponseEntity<Object> getYxSalesCommissions(YxSalesCommissionQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(yxSalesCommissionService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @Log("查询月份")
    @GetMapping("/findMonth")
    public ResponseEntity findMonth(){
        List<String> list=yxSalesCommissionService.findMonth();
        return new ResponseEntity(list,HttpStatus.OK);
    }

}